436de5
@@ -142,7 +142,7 @@
public HiveConnection(String uri, Properties info) throws SQLException {
     // open client session
     openSession();
 
-    configureConnection();
+    configureConnection(connParams.getDbName());
   }
 
   private void openTransport() throws SQLException {
@@ -276,7 +276,7 @@
private void openSession() throws SQLException {
     isClosed = false;
   }
 
-  private void configureConnection() throws SQLException {
+  private void configureConnection(String dbName) throws SQLException {
     // set the hive variable in session state for local mode
     if (isEmbeddedMode) {
       if (!hiveVarMap.isEmpty()) {
@@ -293,6 +293,8 @@
private void configureConnection() throws SQLException {
       for (Entry<String, String> hiveVar : hiveVarMap.entrySet()) {
         stmt.execute("set hivevar:" + hiveVar.getKey() + "=" + hiveVar.getValue());
       }
+      if(dbName!=null)
+        stmt.execute("use "+dbName);
       stmt.close();
     }
   }
